package com.kuaiying.kuai.ying.model.admin;

import com.jfinal.plugin.activerecord.Model;
import com.jfinal.plugin.activerecord.Page;

public class AdminModel extends Model<AdminModel>{

	private static final long serialVersionUID = -6984293973714614241L;
	
	public static final AdminModel me = new AdminModel();
	
	private static final String USER_CACHE = "admin";
	
	public AdminModel(){
		super( );
	}
	/**
	 * 所有 sql 与业务逻辑写在 Model 或 Service 中，不要写在 Controller 中，养成好习惯，有利于大型项目的开发与维护
	 */
	public Page<AdminModel> paginate(int pageNumber, int pageSize) {
		return paginate(pageNumber, pageSize, "select *", "from  admin order by id asc");
	}
	
	/**
	 * 根據用戶名和用戶密碼驗證用戶是否存在
	 * @param userName：用戶名
	 * @param pwd：用戶密碼
	 * @return：用戶信息或null
	 */
	public AdminModel getUserByNameAndPwd(String userName, String pwd){
		String sql = "select * from admin where name = '" + userName + "' and password ='" +  pwd + "'" ;
		System.out.println( sql );
		
		AdminModel user = me.findFirst(sql);
		
		return user;
	}


}


